/*******************************************************************************
 * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
 * Distributed under license by Red Hat, Inc. All rights reserved.
 * This program is made available under the terms of the
 * Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Exadel, Inc. and Red Hat, Inc. - initial API and implementation
 ******************************************************************************/ 
package demo;

import javax.ejb.EJB;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import cl.gob.ips.offline.jbpm.JBPMBean;
import cl.gob.ips.offline.jbpm.JBPMBeanRemote;

import demo.dao.JBPMDao;

public class IngresarSolicitudAction extends org.apache.struts.action.Action {

	@EJB
    JBPMBeanRemote beanRemote = new JBPMBean(); 
    public IngresarSolicitudAction() {
    }

    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {

       //	JBPMDao dao = new JBPMDao();
    	
    	
    	String user =   request.getParameter("usuario");
    	if(null == user){
    		return mapping.findForward("error");    		
    	}else{
    		System.out.println("usuario " + user);
    	       String nombreEjecutivoCAP = user;
    	       String key = java.util.UUID.randomUUID().toString();       
    	       beanRemote.inicializaProceso("procesoIPS" , key, user);
    	       //String key = dao.invocarServicioIniciaProceso(nombreEjecutivoCAP);
    	      
    	       IngresarSolicitudForm formulario = (IngresarSolicitudForm) form;
    	       formulario.setKey(key);
    	      
    	       return mapping.findForward("success");
    	}
    	
    }
}